<template>
  <div>
    <textarea ref="copy" class="copy" readonly />
  </div>
</template>

<script>
export default {
  name: "Copy",
  props: {
    successMsg: String,
    errorMsg: String
  },
  methods: {
    copy(copyStr) {
      if (!copyStr) {
        return;
      }
      let input = this.$refs.copy;
      input.value = copyStr;
      input.focus();
      input.setSelectionRange(0, 500);
      if (document.execCommand("copy")) {
        this.$toast(this.successMsg);
      } else {
        this.$toast(this.errorMsg);
      }
      input.blur();
    }
  }
};
</script>

<style scoped>
.copy {
  position: absolute;
  left: -1000px;
  z-index: -1000;
}
</style>